package pl.smath.parser.text;

import junit.framework.TestCase;
import pl.smath.expression.ProductTerm;
import pl.smath.expression.Term;
import pl.smath.parser.ExpressionParser;


public class ParserTestCase extends TestCase {

	/** 
	 * Test data for parser. 
	 */
	private static final String[] testData = {
		"2",
		"x",
		"-12.9",
		"-x",
		"2*3",
		"4/2",
		"8/4/2",
		"2+3",
		"2-3",
		"2*3-12",
		"2-12*2",
//		"2-3--4", To jest zamieniane na 2-3+4 czy to zle?
		"3+x",
		"x+x+x",
		"x-x-x",
		"x-(x-x)",
		"x+(x-x)",
		"x^y",
		"x^y^z",
		"3*x^2+2*x^2",
		"x^4+3*x^3+x^2-x-(x^3-2*x^2-x)",
		"(x+2)*(x+3)-5*(x-2)",
		"(3*x)^2+(2*x)^a",
		"1.5*3.2",
		"x+3+(x+5)" 
	};
	
	public void testData() {
		Term expression;
		TextParser parser = new TextParser();
		
		for(int i = 0; i < testData.length; i++){

//			System.out.println("Processing: " + testData[i]);
			expression = parser.parse( testData[i] );
		
			String result = expression != null? expression.toString() : "null";
			assertEquals(testData[i], result);
		}
	}
	
	
	/**
	 * Sprawdzenie jak sie zachowa parser przy wpisaniu wielu minusow
	 */
	public void testMultipleMinuses() {
		Term expression;
		ExpressionParser parser = new ExpressionParser();
		
		expression = parser.parseText( "3--4" );
		assertEquals("3+4", expression.toString());
		
	}
	
	/**
	 * Sprawdzenie jak sie zachowa parser przy wpisaniu wielu minusow
	 */
	public void testMinusPower() {
		Term expression;
		ExpressionParser parser = new ExpressionParser();
		
		expression = parser.parseText( "-x^2" );
		assertTrue(expression.isNegative());
		
	}
	
	/**
	 */
	public void testProductType() {
		Term expression;
		ExpressionParser parser = new ExpressionParser();
		
		expression = parser.parseText( "3*4/2" );
		assertTrue(expression instanceof ProductTerm);
		
	}
	
	/**
	 */
	public void testProductType2() {
		Term expression;
		ExpressionParser parser = new ExpressionParser();
		
		expression = parser.parseText( "x/x*x" );
		assertTrue(expression instanceof ProductTerm);
		
	}
	
}
